package tree;

/**
 * @author : Rookie
 * @description : 二叉树最大深度
 * @date : 2023/10/11
 */
public class MaxDepthOfBinaryTree {

    public static void main(String[] args) {
        int[] input = {1, 2, 2, 3, 4, 4, 3, 5, -1, -1, 6, 6, -1, -1, 5};
        TreeNode root = BinaryTreeUtil.buildTree(input);
        System.out.println("二叉树的最大深度是：" + getMaxDepth(root));
    }

    private static int getMaxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int leftDepth = getMaxDepth(root.left);
        int rightDepth = getMaxDepth(root.right);
        return 1+Math.max(leftDepth,rightDepth);
    }
}
